/*
 * Copyright 2013 Agustina Martinez-Garcia

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */
package uk.ljmu.fedoraifz.utilities;

import java.util.HashMap;
/**
 * TODO See how to change this to manage errors from here??
 */
public class ResultsTemplating {
    private boolean fedora3;
    private boolean errorPage;
    private String resultContents;
    
    public static final HashMap<String, String> fedoraErrorCodes = new HashMap<String, String>();
	static {
		fedoraErrorCodes.put("authorization", "Authorization errors when accesing the given object."); 
		fedoraErrorCodes.put("DatastreamLockedException", "Errors managing object datastreams.");
		fedoraErrorCodes.put("DatastreamNotFoundException", "Datastream not found for the object.");
		fedoraErrorCodes.put("GeneralException", "General error when performing operation in the object, contact the the administrator.");
		fedoraErrorCodes.put("HttpServiceNotFoundException", "Connection errors when trying to access Fedora instance");
		fedoraErrorCodes.put("LowlevelStorageException", "Errors when storing data in the repository, contact the the administrator.");
		fedoraErrorCodes.put("LowlevelStorageInconsistencyException", "Errors when storing data in the repository, contact the the administrator.");
		fedoraErrorCodes.put("MalformedPidException", "Errors in the PID, invalid format. Check the format.");
		fedoraErrorCodes.put("MethodNotFoundException", "Operation not found in the repository, check the operation.");
		fedoraErrorCodes.put("MethodParmNotFoundException", "Errors in the parameters of the request, contact the the administrator.");
		fedoraErrorCodes.put("ObjectAlreadyInLowlevelStorageException", "Revise the PID in your spreadsheet, attempting to store an object which already exists.");
		fedoraErrorCodes.put("ObjectDependencyException", "Check the spreadsheet, error in objects' relationships, e.g. an object is a member of another that is not stored yet.");
		fedoraErrorCodes.put("ObjectExistsException", "Revise the PID in your spreadsheet, attempting to store an object which already exists.");
		fedoraErrorCodes.put("ObjectIntegrityException", "Storage issues for the given object, contact the the administrator.");
		fedoraErrorCodes.put("ObjectLockedException", "Storage issues for the given object, contact the the administrator.");
		fedoraErrorCodes.put("ObjectNotFoundException", "Attempting to work with an object which does not exist in the repository, contact the the administrator.");
		fedoraErrorCodes.put("ObjectNotInLowlevelStorageException", "Storage issues for the given object, contact the the administrator.");
		fedoraErrorCodes.put("ObjectValidityException", "Object not valid, contact the the administrator.");
		fedoraErrorCodes.put("ResourceIndexException", "Error while updating the triplestore, contact the the administrator.");
		fedoraErrorCodes.put("ValidationException", "Object FOXML not well formed, contact the the administrator.");
		fedoraErrorCodes.put("java.lang.NullPointerException", "Error in request, contact the administrator");
	}
    /**
     * @param errorPage the errorPage to set
     */
    public void setErrorPage(boolean errorPage) {
	this.errorPage = errorPage;
    }
    /**
     * @return the errorPage
     */
    public boolean isErrorPage() {
	return errorPage;
    }
    /**
     * @param resultContents the resultContents to set
     */
    public void setResultContents(String resultContents) {
	this.resultContents = resultContents;
    }
    /**
     * @return the resultContents
     */
    public String getResultContents() {
	return resultContents;
    }
    public ResultsTemplating(String contents, boolean isFedora3){
	this.fedora3 = isFedora3;
	this.resultContents = contents;
	this.errorPage = checkIfErrorPage(contents);
    }
    
    public ResultsTemplating(String contents, boolean isFedora3, boolean isError){
	this.fedora3 = isFedora3;
	this.resultContents = contents;
	this.errorPage = isError;
    }
    // TODO NOT IMPLEMENTED
    private boolean checkIfErrorPage(String contents) {
	if (fedora3) {
	    //fedora 3 version
	    
	} else {
	    //Fedora 3.4. the error management is different
	}
	
	return false;
    }
}
